<template>
  <div class="wallet-container">
    <!-- Header部分 -->
    <header class="wallet-header">
      <div class="header-content">
        <img :src="user.userImg" alt="用户头像" class="user-avatar">
        <div class="user-info">
          <h3 class="user-id">{{ user.userId }}</h3>
          <p class="user-name">{{ user.userName }}</p>
        </div>
      </div>
    </header>

    <!-- 钱包信息部分 -->
    <div class="wallet-content">
      <div class="wallet-card">
        <h2 class="wallet-title">我的钱包</h2>

        <div class="balance-section">
          <p class="balance-label">账户余额</p>
          <p class="balance-amount">¥{{ wallet.balance }}</p>
        </div>

        <div class="wallet-details">
          <div class="detail-item">
            <span class="detail-label">冻结金额</span>
            <span class="detail-value">¥{{ wallet.frozenAmount }}</span>
          </div>
          <div class="detail-item">
            <span class="detail-label">创建时间</span>
            <span class="detail-value">{{ wallet.createTime }}</span>
          </div>
          <div class="detail-item">
            <span class="detail-label">透支权限</span>
            <span class="detail-value">{{ wallet.allowedOverdraft ? '已开通' : '未开通' }}</span>
          </div>
        </div>

        <div v-if="!wallet.allowedOverdraft" class="promotion-section">
          <p class="promotion-text">购买饿了么会员卡，增加透支额度{{wallet.overdraftLimit}}元</p>
          <button class="promotion-btn" @click="toVIPUpgrade">立即开通</button>
        </div>
      </div>

      <div class="action-buttons">
        <button class="action-btn recharge" @click="toPayment(0)">
          <i class="icon">💰</i>
          <span>充值</span>
        </button>
        <button class="action-btn withdraw" @click="toPayment(1)">
          <i class="icon">💳</i>
          <span>提现</span>
        </button>
        <button class="action-btn record" @click="toTransition">
          <i class="icon">📊</i>
          <span>收支明细</span>
        </button>
      </div>
    </div>

    <!-- 底部菜单部分 -->
    <Footer></Footer>
  </div>
</template>

<script>
import { ref, onMounted, getCurrentInstance } from 'vue';
import { useRouter } from 'vue-router';
import Footer from '../components/Footer.vue';
import axios from 'axios';
import qs from 'qs';
import router from '../router';

export default {
  name: 'WalletManagement',
  setup() {
    const user = ref({});
    const wallet = ref({});
    const {proxy}=getCurrentInstance();

    onMounted(() => {
      const getWalletInfo = async () => {
        try {
          const response = await axios.get(`WalletController/getWalletInfoById/${user.value.userId}`, qs.stringify({}));
          wallet.value = response.data;
        } catch (error) {
          console.error(error);
        }
      };
      user.value = proxy.$getSessionStorage('user');
      getWalletInfo();
    });

    const router = useRouter();

    const toVIPUpgrade = () => {
      router.push({ path: 'vipUpgrade' });
    };

    const toPayment = (status) => {
      router.push({ path: 'paymentExcludeOrders',query:{status} });
    };

    const toTransition = () => {
      router.push({ path: 'transition' });
    };

    return{
      user,
      wallet,
      toVIPUpgrade,
      toPayment,
      toTransition
    };
  },
  components:{
    Footer
  }
};
</script>

<style scoped>
.wallet-container {
  font-family: 'PingFang SC', 'Helvetica Neue', Arial, sans-serif;
  background-color: #f5f5f5;
  min-height: 100vh;
  padding-bottom: 5vw; /* 为底部导航栏留出空间 */
}

/* Header部分样式 */
.wallet-header {
  background: linear-gradient(135deg, #0097ff, #0066cc);
  color: white;
  padding: 20px 15px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.header-content {
  display: flex;
  align-items: center;
}

.user-avatar {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.3);
  object-fit: cover;
}

.user-info {
  margin-left: 15px;
}

.user-id {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}

.user-name {
  margin: 5px 0 0;
  font-size: 14px;
  opacity: 0.9;
}

/* 钱包内容部分 */
.wallet-content {
  padding: 15px;
}

.wallet-card {
  background: white;
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
  margin-bottom: 20px;
}

.wallet-title {
  margin: 0 0 20px;
  font-size: 18px;
  color: #333;
  font-weight: 600;
  padding-bottom: 10px;
  border-bottom: 1px solid #f0f0f0;
}

.balance-section {
  text-align: center;
  margin-bottom: 25px;
}

.balance-label {
  margin: 0;
  font-size: 14px;
  color: #666;
}

.balance-amount {
  margin: 10px 0 0;
  font-size: 32px;
  font-weight: 700;
  color: #0097ff;
}

.wallet-details {
  margin-top: 20px;
}

.detail-item {
  display: flex;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid #f5f5f5;
}

.detail-item:last-child {
  border-bottom: none;
}

.detail-label {
  font-size: 15px;
  color: #666;
}

.detail-value {
  font-size: 15px;
  color: #333;
  font-weight: 500;
}

.promotion-section {
  background: linear-gradient(135deg, #fff8e6, #ffeed6);
  border-radius: 8px;
  padding: 15px;
  margin-top: 20px;
  text-align: center;
}

.promotion-text {
  margin: 0 0 10px;
  font-size: 14px;
  color: #ff9500;
}

.promotion-btn {
  background: linear-gradient(135deg, #ff9500, #ff6b00);
  color: white;
  border: none;
  border-radius: 20px;
  padding: 8px 20px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(255, 149, 0, 0.2);
  transition: all 0.3s ease;
}

.promotion-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(255, 149, 0, 0.3);
}

/* 操作按钮区域 */
.action-buttons {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.action-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: white;
  border: none;
  border-radius: 10px;
  padding: 15px 5px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
  cursor: pointer;
  transition: all 0.3s ease;
}

.action-btn:hover {
  transform: translateY(-3px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.action-btn .icon {
  font-size: 24px;
  margin-bottom: 8px;
}

.action-btn span {
  font-size: 14px;
  color: #333;
}

.recharge {
  background: linear-gradient(135deg, #e6f7ff, #d0f0ff);
}

.withdraw {
  background: linear-gradient(135deg, #f0fff0, #e0ffe0);
}

.record {
  background: linear-gradient(135deg, #fff0f5, #ffe0eb);
}

/* 响应式设计 */
@media (max-width: 375px) {
  .balance-amount {
    font-size: 28px;
  }

  .action-btn {
    padding: 12px 5px;
  }

  .action-btn .icon {
    font-size: 20px;
  }

  .action-btn span {
    font-size: 12px;
  }
}
/* 底部菜单样式 */
.footer {
  width: 100%;
  height: 5vw;
  border-top: solid 1px #DDD;
  background-color: #fff;
  position: fixed;
  left: 0;
  bottom: 0;
  display: flex;
  justify-content: space-around;
  align-items: center;
  list-style: none;
  margin: 0;
  padding: 0;
}
</style>